package com.dmai.aiet.epc.archive.util;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class DateUtils {


    /**
     * 获取时间区间内的天
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public static List<String> getTwoDaysDay(Long dateStart, Long dateEnd) {
        List<String> dateList = new ArrayList<>();
        LocalDate startDate = Instant.ofEpochMilli(dateStart).atZone(ZoneOffset.ofHours(8)).toLocalDate();
        LocalDate endDate = Instant.ofEpochMilli(dateEnd).atZone(ZoneOffset.ofHours(8)).toLocalDate();

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        dateList.add(startDate.toString());
        while (startDate.isBefore(endDate)) {
            startDate = startDate.plusDays(1);
            dateList.add(startDate.format(formatter));
        }

        return dateList;
    }

    /**
     * 获取时间区间内的天
     * @param dateStart
     * @param dateEnd
     * @return
     */
    public static List<String> getTwoDaysMonth(Long dateStart, Long dateEnd) {
        List<String> dateList = new ArrayList<>();
        LocalDate startDate = Instant.ofEpochMilli(dateStart).atZone(ZoneOffset.ofHours(8)).toLocalDate();
        LocalDate endDate = Instant.ofEpochMilli(dateEnd).atZone(ZoneOffset.ofHours(8)).toLocalDate();

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        dateList.add(startDate.toString());
        while (startDate.isBefore(endDate)) {
            startDate = startDate.plusMonths(1);
            dateList.add(startDate.format(formatter));
        }

        return dateList;
    }

}
